package com.yanqu.road.server.cmd.manor.fishpond;

import com.yanqu.road.entity.manor.FedFish;
import com.yanqu.road.pb.manor.FishPondProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.manor.ManorFishPondModel;
import com.yanqu.road.server.gameplayer.module.manor.ManorModule;
import com.yanqu.road.server.pb.FishPondPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;

/**
 * @author ：zfr
 * @date ：2021/10/12 16:48
 */
@Cmd(code = GameProtocol.S_FISH_POND_FEED_FISH, desc = "鱼塘喂鱼")
public class FeedFishCmd extends AbstractCommand {
    private int feedFishId;
    private int fishSkillId;
    private List<FedFish> fedFishList;
    private long exp;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        FishPondProto.FeedFishReqMsg msg = FishPondProto.FeedFishReqMsg.parseFrom(packet.getBytes());
        feedFishId = msg.getFeedFishId();
        fishSkillId = msg.getFishSkillId();
        fedFishList = FishPondPb.parseFedFishList(msg.getFedFishList());
        exp = msg.getExp();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ManorFishPondModel manorFishPondModel = player.getModule(ManorModule.class).getManorFishPondModel();
        if (manorFishPondModel != null) {
            ret = manorFishPondModel.feedFish(feedFishId, fishSkillId, fedFishList, exp);
        } else {
            ret = GameErrorCode.E_FISH_POND_IS_LOCK;
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            FishPondProto.FeedFishRespMsg.Builder respMsg = FishPondProto.FeedFishRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_FISH_POND_FEED_FISH, respMsg);
        }
    }
}
